<?php

namespace myshop\common\middleware;

/**
 * 记录API日志中间键
 */
class AdminApiLogMiddleware
{
    const NOT_LOG_RULE = [];
    const NOT_API_METHOD= ['get'];
    public function handle($request, \Closure $next)
    {
        $route = $request->rule();
        $rule = $route->getRule();
        $ip = $request->ip();
        $method = $route->getMethod();
        $logApiTag = false;
        //先判断请求方式 是否记录日志 如果需要，再判断路由
        if(!empty(self::NOT_API_METHOD) && in_array($method,self::NOT_API_METHOD)){
            // todo 记录日志
            $logApiTag = true;
        }
        if($logApiTag){
           if(!empty(self::NOT_API_METHOD) && in_array($rule,self::NOT_LOG_RULE)) {
               $logApiTag = false;
           }
        }
        if($logApiTag) {
            //todo 记录请求日志
        }
        return $next($request);

    }
}